package com.szbber.commen.api

import android.content.Context
import com.szbber.commen.bean.*

/**
 * 接口资源
 * @author ssq
 */
object Repository {

    /**
     * 预处理数据(错误)
     * @param context 跳至登录页的上下文
     */
    private suspend fun <T : BaseBean> preprocessData(baseBean: T?, context: Context?): T =
        if (baseBean?.code == 200) {// 成功
            // 返回数据
            baseBean
        }
        else{
            throw ApiException()
        }

    private fun getMap(
        vararg s: String
    ): Map<String, String>? {
        val map: MutableMap<String, String> =
            HashMap()
        if (s.size % 2 != 0) {
            return null
        } else {
            var i = 0
            while (i < s.size) {
                map[s[i]] = s[++i]
                i++
            }
        }
        return map
    }

    suspend fun getBanners(context: Context?, vararg query: String?): DeptBean =
        NetworkService.api.getBanners(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getHospitalBean(context: Context?, vararg query: String?): HospitalBean =
        NetworkService.api.getHospitalBean(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getDeptBean(context: Context?, vararg query: String?): DeptBean =
        NetworkService.api.getDeptBean(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getDistrictBean(context: Context?, vararg query: String?): DistrictBean =
        NetworkService.api.getDistrictBean(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getRoomBean(context: Context?, vararg query: String?): RoomBean =
        NetworkService.api.getRoomBean(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getBedBean(context: Context?, vararg query: String?): BedBean =
        NetworkService.api.getBedBean(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getNurseLevel(context: Context?, vararg query: String?): NurseLevelListBean =
        NetworkService.api.getNurseLevel(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getEditNurseLevel(context: Context?, vararg query: String?): IntDataBean =
        NetworkService.api.getEditNurseLevel(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getCareLevelList(context: Context?, vararg query: String?): CareLevelListBean =
        NetworkService.api.getCareLevelList(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getEditCareLevel(context: Context?, vararg query: String?): IntDataBean =
        NetworkService.api.getEditCareLevel(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getBedCardInfo(context: Context?, vararg query: String?): BedCardInfoBean =
        NetworkService.api.getBedCardInfo(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getPatientList(context: Context?, vararg query: String?): PatientListBean =
        NetworkService.api.getPatientList(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getPatientInfo(context: Context?, vararg query: String?): PatientDetailsBean =
        NetworkService.api.getPatientInfo(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun editPatientInfo(context: Context?, vararg query: String?): IntDataBean =
        NetworkService.api.editPatientInfo(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getDoctorList(context: Context?, vararg query: String?): DoctorListBean =
        NetworkService.api.getDoctorList(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getNurseList(context: Context?, vararg query: String?): NurseListBean =
        NetworkService.api.getNurseList(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun addCareLevel(context: Context?, vararg query: String?): IntDataBean =
        NetworkService.api.addCareLevel(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun doctorOrderList(context: Context?, vararg query: String?): DoctorOrderBean =
        NetworkService.api.doctorOrderList(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun addMessage(context: Context?, vararg query: String?): IntDataBean =
        NetworkService.api.addMessage(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getMessageList(context: Context?, vararg query: String?): MessageListBean =
        NetworkService.api.getMessageList(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getSchedule(context: Context?, vararg query: String?): ScheduleBean =
        NetworkService.api.getSchedule(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun addNurseLevel(context: Context?, vararg query: String?): IntDataBean =
        NetworkService.api.addNurseLevel(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun deteleNurseLevel(context: Context?, vararg query: String?): IntDataBean =
        NetworkService.api.deteleNurseLevel(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun addNurseLevelLabel(context: Context?, vararg query: String?): IntDataBean =
        NetworkService.api.addNurseLevelLabel(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun deleteNurseLevelLabel(context: Context?, vararg query: String?): IntDataBean =
        NetworkService.api.deleteNurseLevelLabel(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun deleteCareLevel(context: Context?, vararg query: String?): IntDataBean =
        NetworkService.api.deleteCareLevel(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }

    suspend fun getDoorPatient(context: Context?, vararg query: String?): DoorPatientBean =
        NetworkService.api.getDoorPatient(getMap(*query as Array<out String>)).let { preprocessData(it, context)
    }




}